<?php
/**
 * 招商交建公众服务平台方发行渠道接口集
 */

namespace Framework;

use crypt\Aes;
use Framework\Hope;
use PHPUnit\Util\Json;

/**
 * 支持在非ThinkPHP环境下使用
 */
defined('NOW_TIME') || define('NOW_TIME', $_SERVER['REQUEST_TIME']);
defined('IS_GET')   || define('IS_GET',   $_SERVER['REQUEST_METHOD'] == 'GET');

class Cmb {
    private $domain = ''; // host
	private $aes_key = null;
	private $aes_key_pwd = null;
	private $public_rsa_key = null;
	private $private_rsa_key = null;

    private $time = ''; // current timestamp. The unit is ms.
	private $timestamp = '';    // yyyy-MM-dd HH:mm:ss

	private $encryAesKey = null;    // The RSAWITHAES model & Must be transmitted.
	private $bizContent = null; // json string & Not encrypted by default.

	private $pub_data = []; // public param.
	private $data = []; // request param.

	private $is_debug = false;


    /**
     * 可以在实例化类的时候配置数据，也可以在下面的connect方法中配置数据
     * Ftp constructor.
     */
    public function __construct($C = [])
    {
        empty($C) OR $this -> initialize($C);
    }

    /**
     * 初始化数据
     * @param array $C 配置文件数组
     */
    public function initialize($C = []){
        $this -> domain = $C['domain'];

		$this -> aes_key_pwd = Hope::pkcs5Str($C['aes_key_pwd']);
//	    $this -> aes_key = @base64_encode(openssl_encrypt($C['aes_key'], 'AES-128-ECB', $this -> aes_key_pwd, 0));   // aes-128-cbc

	    $this -> public_rsa_key = $C['public_rsa_key'];
	    $this -> private_rsa_key = openssl_pkey_get_private($C['private_rsa_key']);

	    $this -> time = intval(microtime(true) * 1000); // current timestamp.
	    $this -> timestamp = date("Y-m-d H:m:s", time());

		$this -> pub_data = [
			'accessNo'  =>  $C['accessNo'],
			'format'  =>  $C['format'],
			'charset'  =>  $C['charset'],
			'encryptType'  =>  $C['encryptType'],    // AES/RSA/RSAWITHAES
			'timestamp'  =>  $this -> timestamp,    // yyyy-MM-dd HH:mm:ss
			'version'  =>  $C['version'],
		];

	    if ($this -> pub_data['encryptType'] == "RSAWITHAES") {
//		    $this -> aes_key = $this -> aes_key_pwd;
		    $this -> aes_key = substr(md5($this -> time), 5, 16);
//			$this -> aes_key = 'ca4503f717fb93d3';
	    } else {
//		    dump("需要加密的字符串： " . $C['aes_key']);
		    $this -> aes_key = @openssl_encrypt($C['aes_key'], 'AES-128-ECB', $this -> aes_key_pwd, 0);
	    }

		$this -> is_debug = $C['is_debug'];
    }

    /**
     * 卡签发行状态查询接口   Issuance status query
     * @param array $server The server's ip or bind domain.
     * @return bool
     */
    public function ISQ($Q = []) {
        $url = $this -> domain . '/pubsv-xz-nm/ioapi/issueactive/query';
	    if ($this -> is_debug) {
//			$url = str_ireplace('pubsv-xz-nm','pubsv-xz', $url);
		    $url = str_ireplace('pubsv-xz-nm','pubsvservice', $url);
	    }

	    $Q['time'] = $this -> time;
	    $bizContent = json_encode($Q, JSON_UNESCAPED_UNICODE);
	    $this -> bizContent = @openssl_encrypt($bizContent, 'AES-128-ECB', $this -> aes_key, OPENSSL_RAW_DATA);

	    $this -> bizContent = base64_encode($this -> bizContent);

	    $encryAesKey = RSA_openssl($this -> aes_key, 'encode');
	    $this -> encryAesKey = $encryAesKey;

	    $decryAesKey = RSA_openssl($this -> encryAesKey, 'decode');

	    $this -> data = [
		    'encryAesKey'  =>  $encryAesKey,
		    'bizContent'  =>  $this -> bizContent,
	    ];
	    $this -> data = array_merge($this -> data, $this -> pub_data);

	    $raw = Hope::http_request($url, $this -> data);
	    $res = $raw = json_decode($raw, true);
	    $res['Q'] = $Q;
	    $res['private_rsa_decode_key'] = config('app.cmb.private_rsa_decode_key');
	    $res['decryAesKey'] = $decryAesKey = RSA_openssl($raw['encryAesKey'], 'decode', 'cmbr');
	    $res['unpackContent'] = $bizContent = openssl_decrypt(base64_decode($raw['bizContent']), 'AES-128-ECB', $res['decryAesKey'], OPENSSL_RAW_DATA);

	    return $res;
    }

	/**
	 * 发送卡签发行激活校验短信接口   Send the card issuing line to activate the verification SMS
	 * @return bool
	 */
	public function SMS($Q =[]) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/issueactive/sendmsg';
		$res = $this -> createFun($Q, $url);
		return $res;
	}

	/**
	 * 卡签验证码校验接口   Card signature verification code verification
	 * @return bool
	 */
	public function VSMS($Q = []) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/issueactive/verifymsg';
		$res = $this -> createFun($Q, $url);
		return $res;
	}

	/**
	 * 发行激活上传图片   Release activates uploading images
	 * @return bool
	 */
	public function RAUI($Q = []) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/issueactive/uploadPic';
		$res = $this -> createFun($Q, $url);
		return $res;
	}

	/**
	 * 获取写车辆信息指令   Get instructions to write vehicle information
	 * @return bool
	 */
	public function GITWVI($Q = []) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/issueactive/writeVehicle';
		$res = $this -> createFun($Q, $url);
		return $res;
	}

	/**
	 * 获取写系统信息指令   Gets the instruction to write system information
	 * @return bool
	 */
	public function GITWSI($Q = []) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/issueactive/writeSystem';
		$res = $this -> createFun($Q, $url);
		return $res;
	}

	/**
	 * 写OBU成功确认   Write the OBU to confirm successfully
	 * @return bool
	 */
	public function WOBUC($Q = []) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/issueactive/confirmObu';
		$res = $this -> createFun($Q, $url);
		return $res;
	}

	/**
	 * 获取卡片文件写卡指令接口   Obtain the card file write card instruction
	 * @return bool
	 */
	public function OCWCI($Q = [], $snum){
		switch ($snum) {
			case "0015":
				$url = $this -> domain . '/pubsv-xz-nm/ioapi/issueactive/write0015';
				break;
			case "0016":
			default:
				$url = $this -> domain . '/pubsv-xz-nm/ioapi/issueactive/write0016';
				break;
		}

		$res = $this -> createFun($Q, $url);
		return $res;
	}

	/**
	 * 写卡成功确认   Confirm that the card is written successfully
	 * @return bool
	 */
	public function CTTCIWS($Q = []) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/issueactive/confirmCard';
		$res = $this -> createFun($Q, $url);
		return $res;
	}

	/**
	 * 查询ETC客户信息   Query ETC customer information
	 * @return bool
	 */
	public function QECI($Q = []) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/applyissue/queryCustomerInfo';
		$res = $this -> createFun($Q, $url);
		return $res;
	}

	/**
	 * 录入ETC客户信息   Enter ETC customer information
	 * @return bool
	 */
	public function EECI($Q = []) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/applyissue/addCustomerInfo';
		$res = $this -> createFun($Q, $url);
		return $res;
	}

	/**
	 * 更新ETC客户信息   Update ETC customer information
	 * @return bool
	 */
	public function UECI() {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/applyissue/updateCustomerInfo';

		$Q['time'] = $this -> time;
		$this -> data = $Q;
		$res = Hope::http_request($url, $this -> data);

		return $res;
	}

	/**
	 * 录入经办人信息   Enter the information of the person in charge
	 * @return bool
	 */
	public function EIPC($Q = []) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/applyissue/agent/add';
		if ($this -> is_debug) {
			//			$url = str_ireplace('pubsv-xz-nm','pubsv-xz', $url);
			$url = str_ireplace('pubsv-xz-nm','pubsvservice', $url);
		}

		$Q['time'] = $this -> time;
		$bizContent = json_encode($Q, JSON_UNESCAPED_UNICODE);
		$this -> bizContent = @openssl_encrypt($bizContent, 'AES-128-ECB', $this -> aes_key, OPENSSL_RAW_DATA);

		$this -> bizContent = base64_encode($this -> bizContent);

		if ($this -> pub_data['encryptType'] == "RSAWITHAES") {

		} else {

		}

		$encryAesKey = RSA_openssl($this -> aes_key, 'encode');
		$this -> encryAesKey = $encryAesKey;

		$decryAesKey = RSA_openssl($this -> encryAesKey, 'decode');

		$this -> data = [
			'encryAesKey'  =>  $encryAesKey,
			'bizContent'  =>  $this -> bizContent,
		];
		$this -> data = array_merge($this -> data, $this -> pub_data);

		/**
		 * {
		"code": "SUCCESS",
		"msg": "成功",
		"receiveTime": "2022-12-02 15:50:05",
		"bizContent": "ASwmx2brClSF4VoYSr+Rwg==",
		"format": "String",
		"encryAesKey": "kIx7kcUksd5XYB7Ko4ytzCidtkhMg2xk4JTkBk+7L+B6jJM/o8vJsZVRhnlOEyoSjFaKcpyRdz4THgtrmwdKAMZO9tAddC+UlqTtPbfzlJ/p0Dr/oiynalFWjgqEezKi9TyghBXQlLwS68mnJuPaauJcK634UgwlLW79ZweDd/Q="
		}
		 */
		dump($this -> data);
		$raw = Hope::http_request($url, $this -> data);
		dump($raw);
		$res = $raw = json_decode($raw, true);
		$res['Q'] = $Q;
		$res['private_rsa_decode_key'] = config('app.cmb.private_rsa_decode_key');
		$res['decryAesKey'] = $decryAesKey = RSA_openssl($raw['encryAesKey'], 'decode', 'cmbr');
		$res['unpackContent'] = $bizContent = openssl_decrypt(base64_decode($raw['bizContent']), 'AES-128-ECB', $res['decryAesKey'], OPENSSL_RAW_DATA);

		return $res;
	}

	/**
	 * 车辆卡签校验查询接口(本省)   Vehicle card verification query interface (national and provincial)
	 * @return bool
	 */
	public function VCVQIP($Q = []) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/applyissue/checkVehilce';
		if ($this -> is_debug) {
//			$url = str_ireplace('pubsv-xz-nm','pubsv-xz', $url);
			$url = str_ireplace('pubsv-xz-nm','pubsvservice', $url);
		}

		$Q['time'] = $this -> time;
		$bizContent = json_encode($Q, JSON_UNESCAPED_UNICODE);
		$this -> bizContent = @openssl_encrypt($bizContent, 'AES-128-ECB', $this -> aes_key, OPENSSL_RAW_DATA);

//	    $AES = new Aes($this -> aes_key, 'AES-128-ECB', '', OPENSSL_RAW_DATA);
//		$this -> bizContent = $AES -> encrypt($bizContent);

		$this -> bizContent = base64_encode($this -> bizContent);

		if ($this -> pub_data['encryptType'] == "RSAWITHAES") {
//			dump("aeskey： " . $this -> aes_key);
//			dump("base64加密后的aeskey： " . base64_decode($this -> aes_key));
//			dump("还原 加密字符串： " . openssl_decrypt(base64_decode($this -> aes_key), 'AES-128-ECB', $this -> aes_key_pwd, 0));
//			dump(strlen($this -> aes_key));
//			dump("bizContent json串： " . $bizContent);
//			dump("bizContent AES加密串： " . $this -> bizContent);
//			dump("还原 bizContent包： " . openssl_decrypt(base64_decode($this -> bizContent), 'AES-128-ECB', $this -> aes_key, OPENSSL_RAW_DATA));
//			dump("还原 bizContent包： " . $AES -> decrypt(base64_decode($this -> bizContent)));
//			dump(strlen($this -> bizContent));
//			print_r(json_encode([ 'a'=>1, 'b'=>2, 'f'=>6]));
		} else {
//		    dump("AES加密key： " . $this -> aes_key_pwd);
//		    dump("AES加密后的aeskey： " . $this -> aes_key);
//			dump("base64加密后的aeskey： " . base64_decode($this -> aes_key));
//		    dump("还原 加密字符串： " . openssl_decrypt(base64_decode($this -> aes_key), 'AES-128-ECB', $this -> aes_key_pwd, 0));
//		    dump("还原 加密字符串： " . openssl_decrypt($this -> aes_key, 'AES-128-ECB', $this -> aes_key_pwd, 0));
//	        dump(strlen($this -> aes_key));
//		    dump("bizContent json串： " . $bizContent);
//		    dump("bizContent AES加密串： " . $this -> bizContent);
//    	    dump(strlen($this -> bizContent));
//    		print_r(json_encode([ 'a'=>1, 'b'=>2, 'f'=>6]));
		}

		$encryAesKey = RSA_openssl($this -> aes_key, 'encode');
		$this -> encryAesKey = $encryAesKey;
//		dump("encryAesKey RSA加密后的AES密钥串： " . $this -> encryAesKey);
//		dump(strlen($this -> encryAesKey));

		$decryAesKey = RSA_openssl($this -> encryAesKey, 'decode');
//	    dump("还原 AES密钥串： " . $decryAesKey);

		$this -> data = [
			'encryAesKey'  =>  $encryAesKey,
			'bizContent'  =>  $this -> bizContent,
		];
		$this -> data = array_merge($this -> data, $this -> pub_data);

		/**
		 * {
			"code": "SUCCESS",
			"msg": "成功",
			"receiveTime": "2022-12-02 15:50:05",
			"bizContent": "ASwmx2brClSF4VoYSr+Rwg==",
			"format": "String",
			"encryAesKey": "kIx7kcUksd5XYB7Ko4ytzCidtkhMg2xk4JTkBk+7L+B6jJM/o8vJsZVRhnlOEyoSjFaKcpyRdz4THgtrmwdKAMZO9tAddC+UlqTtPbfzlJ/p0Dr/oiynalFWjgqEezKi9TyghBXQlLwS68mnJuPaauJcK634UgwlLW79ZweDd/Q="
			}
		 */
		$raw = Hope::http_request($url, $this -> data);
		dump("返回原始数据值： " . $raw);
		$res = $raw = json_decode($raw, true);
		$res['Q'] = $Q;
		$res['private_rsa_decode_key'] = config('app.cmb.private_rsa_decode_key');
		$res['decryAesKey'] = $decryAesKey = RSA_openssl($raw['encryAesKey'], 'decode', 'cmbr');
		$res['unpackContent'] = $bizContent = openssl_decrypt(base64_decode($raw['bizContent']), 'AES-128-ECB', $res['decryAesKey'], OPENSSL_RAW_DATA);

		return $res;
	}

	/**
	 * 车辆卡签校验查询接口(全国和本省)   Vehicle card verification query interface (national and provincial)
	 * @return bool
	 */
	public function VCVQIN($Q = []) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/applyissue/checkAndQueryVehilce';
		if ($this -> is_debug) {
//			$url = str_ireplace('pubsv-xz-nm','pubsv-xz', $url);
			$url = str_ireplace('pubsv-xz-nm','pubsvservice', $url);
		}

		$Q['time'] = $this -> time;
		$bizContent = json_encode($Q, JSON_UNESCAPED_UNICODE);
		$this -> bizContent = @openssl_encrypt($bizContent, 'AES-128-ECB', $this -> aes_key, OPENSSL_RAW_DATA);

//	    $AES = new Aes($this -> aes_key, 'AES-128-ECB', '', OPENSSL_RAW_DATA);
//		$this -> bizContent = $AES -> encrypt($bizContent);

		$this -> bizContent = base64_encode($this -> bizContent);

		if ($this -> pub_data['encryptType'] == "RSAWITHAES") {
//			dump("aeskey： " . $this -> aes_key);
//			dump("base64加密后的aeskey： " . base64_decode($this -> aes_key));
//			dump("还原 加密字符串： " . openssl_decrypt(base64_decode($this -> aes_key), 'AES-128-ECB', $this -> aes_key_pwd, 0));
//			dump(strlen($this -> aes_key));
//			dump("bizContent json串： " . $bizContent);
//			dump("bizContent AES加密串： " . $this -> bizContent);
//			dump("还原 bizContent包： " . openssl_decrypt(base64_decode($this -> bizContent), 'AES-128-ECB', $this -> aes_key, OPENSSL_RAW_DATA));
//			dump("还原 bizContent包： " . $AES -> decrypt(base64_decode($this -> bizContent)));
//			dump(strlen($this -> bizContent));
//			print_r(json_encode([ 'a'=>1, 'b'=>2, 'f'=>6]));
		} else {
//		    dump("AES加密key： " . $this -> aes_key_pwd);
//		    dump("AES加密后的aeskey： " . $this -> aes_key);
//			dump("base64加密后的aeskey： " . base64_decode($this -> aes_key));
//		    dump("还原 加密字符串： " . openssl_decrypt(base64_decode($this -> aes_key), 'AES-128-ECB', $this -> aes_key_pwd, 0));
//		    dump("还原 加密字符串： " . openssl_decrypt($this -> aes_key, 'AES-128-ECB', $this -> aes_key_pwd, 0));
//	        dump(strlen($this -> aes_key));
//		    dump("bizContent json串： " . $bizContent);
//		    dump("bizContent AES加密串： " . $this -> bizContent);
//    	    dump(strlen($this -> bizContent));
//    		print_r(json_encode([ 'a'=>1, 'b'=>2, 'f'=>6]));
		}

		$encryAesKey = RSA_openssl($this -> aes_key, 'encode');
		$this -> encryAesKey = $encryAesKey;
//	    dump("encryAesKey RSA加密后的AES密钥串： " . $this -> encryAesKey);
//	    dump(strlen($this -> encryAesKey));

		$decryAesKey = RSA_openssl($this -> encryAesKey, 'decode');
//	    dump("还原 AES密钥串： " . $decryAesKey);

		$this -> data = [
			'encryAesKey'  =>  $encryAesKey,
			'bizContent'  =>  $this -> bizContent,
		];
		$this -> data = array_merge($this -> data, $this -> pub_data);

		$raw = Hope::http_request($url, $this -> data);
		$res = $raw = json_decode($raw, true);
		$res['Q'] = $Q;
		$res['private_rsa_decode_key'] = config('app.cmb.private_rsa_decode_key');
		$res['decryAesKey'] = $decryAesKey = RSA_openssl($raw['encryAesKey'], 'decode', 'cmbr');
		$res['unpackContent'] = $bizContent = openssl_decrypt(base64_decode($raw['bizContent']), 'AES-128-ECB', $res['decryAesKey'], OPENSSL_RAW_DATA);

		return $res;
	}

	/**
	 * 车辆信息查询接口   Vehicle information query interface
	 * @return bool
	 */
	public function VIQI($Q = []) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/applyissue/queryVehilce';
		$res = $this -> createFun($Q, $url);
		return $res;
	}

	/**
	 * 车辆信息录入接口   Vehicle information entry interface
	 * @return bool
	 */
	public function VIEI($Q = []) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/applyissue/addVehicle';
		$res = $this -> createFun($Q, $url);
		return $res;
	}

	/**
	 * 更新车辆信息接口   Update the vehicle information interface
	 * @return bool
	 */
	public function UVII() {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/applyissue/updateVehicle';

		$Q['time'] = $this -> time;
		$this -> data = $Q;
		$res = Hope::http_request($url, $this -> data);

		return $res;
	}

	/**
	 * 录入线下银行签约信息接口   Enter the offline bank signing information interface
	 * @return bool
	 */
	public function EOBSII($Q = []) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/applyissue/addOrUpdateBankSign';
		$res = $this -> createFun($Q, $url);
		return $res;
	}

	/**
	 * 申办订单提交   Bid for order submission
	 * @return bool
	 */
	public function BOS($Q = []) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/applyissue/submitBusiness';
		$res = $this -> createFun($Q, $url);
		return $res;
	}

	/**
	 * 申办订单详情   Order details
	 * @return bool
	 */
	public function OD($Q = []) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/applyissue/getBusinessDetail';
		$res = $this -> createFun($Q, $url);
		return $res;
	}

	/**
	 * 业务单取消接口   The service order cancels the interface
	 * @return bool
	 */
	public function SOCI() {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/applyissue/cancelBusiness';

		$Q['time'] = $this -> time;
		$this -> data = $Q;
		$res = Hope::http_request($url, $this -> data);

		return $res;
	}

	/**
	 * 获取授权访问token接口   getToken
	 * @return bool
	 */
	public function getToken($Q = []) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/auth/getToken';
		$res = $this -> createFun($Q, $url);
		return $res;
	}

	/**
	 * 查询卡签信息接口   Check card card information
	 * @return bool
	 */
	public function CCCI($Q = []) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/aftersale/queryCardObuInfo';
		$res = $this -> createFun($Q, $url);
		return $res;
	}

	/**
	 * 通知发行渠道变更列表   Notify the distribution channel change list
	 * @return bool
	 */
	public function NTDCCL($Q = []) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/applyissue/issueOrgChangeList';
		$res = $this -> createFun($Q, $url);
		return $res;
	}

	/**
	 * 卡签售后验证码发送接口   The After-sales sms
	 * @return bool
	 */
	public function ASSMS($Q = []) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/aftersale/msg/send';
		$res = $this -> createFun($Q, $url);
		return $res;
	}

	/**
	 * 卡签售后验证码校验接口   The After-sales verify sms
	 * @return bool
	 */
	public function ASVSMS($Q = []) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/aftersale/verifymsg';
		$res = $this -> createFun($Q, $url);
		return $res;
	}

	/**
	 * 卡签注销提交接口   card and obu cancle
	 * @return bool
	 */
	public function CAOC($Q = []) {
		$url = $this -> domain . '/pubsv-xz-nm/ioapi/aftersale/cardObuCancel';
		$res = $this -> createFun($Q, $url);
		return $res;
	}

	/**
	 * create fun.
	 * @param array $Q
	 * @param       $url
	 *
	 * @return mixed
	 */
	private function createFun($Q = [], $url) {


		if ($this -> is_debug) {
			$url = str_ireplace('pubsv-xz-nm','pubsv-xz', $url);
//			$url = str_ireplace('pubsv-xz-nm','pubsvservice', $url);    // pro
		}

		$Q['time'] = $this -> time;
		$bizContent = json_encode($Q, JSON_UNESCAPED_UNICODE);

		$this -> bizContent = @openssl_encrypt($bizContent, 'AES-128-ECB', $this -> aes_key, OPENSSL_RAW_DATA);

		$this -> bizContent = base64_encode($this -> bizContent);

		$encryAesKey = Hope::RSA_openssl($this -> aes_key, 'encode');
		$this -> encryAesKey = $encryAesKey;

		$decryAesKey = Hope::RSA_openssl($this -> encryAesKey, 'decode');

		$this -> data = [
			'encryAesKey'  =>  $encryAesKey,
			'bizContent'  =>  $this -> bizContent,
		];
		$this -> data = array_merge($this -> data, $this -> pub_data);
dd($this -> data);
		$raw = Hope::http_request($url, $this -> data);

		$res = $raw = json_decode($raw, true);
		$res['Q'] = $Q;
//		$res['private_rsa_decode_key'] = config('app.cmb.private_rsa_decode_key');
		$decryAesKey = Hope::RSA_openssl($raw['encryAesKey'], 'decode', 'cmbr');
		$res['decryAesKey'] = $decryAesKey;
		$res['url'] = $url;
		$res['unpackContent'] = $bizContent = openssl_decrypt(base64_decode($raw['bizContent']), 'AES-128-ECB', $res['decryAesKey'], OPENSSL_RAW_DATA);

		return $res;
	}



	private $keys="ZGVtb2RlbW9kZW1vZGVtbw==";//16位字符串base64加密
	private function encrypt($input) {
		$key=base64_decode($this->keys);
		$size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
		$input = $this -> pkcs5_pad($input, $size);
		$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, '');
		$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
		mcrypt_generic_init($td, $key, $iv);
		$data = mcrypt_generic($td, $input);
		mcrypt_generic_deinit($td);
		mcrypt_module_close($td);
		$data = base64_encode($data);
		return $data;
	}
	private function pkcs5_pad ($text, $blocksize) {
		$pad = $blocksize - (strlen($text) % $blocksize);
		return $text . str_repeat(chr($pad), $pad);
	}
}
